VBScript or visual basic script is a scripting language used for developing and designed of automation and scripting tasks. vb script is commonly used for scripting within HMI environments to automate repetitive tasks, such as tag values, visualization task, alarm handling, network error handling, administrative tasks etc. vbscript is more user friendly scripting language so it is mostly used in industial control system. It is based on Microsoft\'s Visual Basic programming language and is primarily used for automating tasks. in wincc vbscript help to designing more user friendly graphical user interface. wincc hmi also support vbscript. this article only for wincc hmi scripting. you can use this script language in wincc software or wincc tia portal.
open or create your project in wincc flexible or wincc tia portal. select HMI and add component to your hmi in this article a button and two input output field and a text field is inserted. after insering these component add input1, input2 tag and select UINT data type in tag table. Assign input1 and input2 tag for input output fields.
to add vbscript in wincc, go to project tree open script and than click to add new vbscript now next step is write a script for hmi. in wincc have two type of script function you can add
after adding script open script in wincc flexible and write a following code in this script example we simply add two input output field value. following are the script subroutine vb script example explanation
after creating no error script select button and open button property and select event in event select button press event and select script
in simulation you can check how your actual work in hmi. after assigning script in button event simulate program to test. when wincc simulation start and value of input output fild is changed. supposed in input field value 124 and input filed value is 124 and than add button is pressed result of these input output filed shown in text field.
in this simple vb script value of increment when increment button is pressed. each click of increment button increase value by 1. so first add button and rename button to increment and a numerical input output field where we show incremental value when button is pressed. Add a script and than add add following script in script editor.
above is the function vbscript in wincc without parameter. This VBScript code defines a function named VBFunction_4 that increments the value of a SmartTag named "tag1" by 1 and then returns the updated value. following is the line by line explanation of vbscript in wincc
after create above script define this vbscript function to button so you can use this script when button clicked. so first goto button property open button event tab and select script.and in input output field declare tag1 in process tag property tab.